//用户管理相关的接口函数

//导入二次封装axios
import request from "@/utils/request";
import type {
  getUserListParams,
  UserListRes,
  addUserParams,
  GetRoleListRes,
} from "./models/userModel";

//枚举接口地址
enum Api {
  getUserListUrl = "/admin/acl/user",
  AddUserUrl = "/admin/acl/user/save",
  getRoleListUrl = "/admin/acl/user/toAssign",
  assignRoleUrl = "/admin/acl/user/doAssign",
}

/**
 * 获取用户列表的接口函数
 * @param
 * @returns
 */
export const getUserListApi = ({
  page,
  limit,
  username,
}: getUserListParams) => {
  return request.get<any, UserListRes>(
    `${Api.getUserListUrl}/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};

/**
 * 添加用户的接口函数
 * @param addUserParams
 * @returns null
 */
export const AddUserApi = (data: addUserParams) => {
  return request.post<any, null>(Api.AddUserUrl, data);
};

/**
 * 根据用户获取角色数据
 * @param id
 * @returns GetRoleListRes
 */
export const getRoleListApi = (id: string) => {
  return request.get<any, GetRoleListRes>(Api.getRoleListUrl + `/${id}`);
};

/**
 * 根据用户分配角色
 * @param id
 * @param roleId
 * @returns null
 */
export const assignRoleApi = (id: string, roleId: string[]) => {
  return request.post<any, null>(
    Api.assignRoleUrl,
    {},
    {
      params: {
        userId: id,
        roleId: roleId + "",
      },
    }
  );
};
